-
Notifications
You must be signed in to change notification settings - Fork 434
Statics #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Statics #146
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than potential edge cases, code style needs updating as well.
test/test.ts
Outdated
@@ -256,4 +256,14 @@ describe('vue-class-component', () => { | |||
expect(parent.value).to.equal('parent') | |||
expect(child.value).to.equal('child') | |||
}) | |||
|
|||
it('forwardStatics', function () { | |||
debugger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
src/component.ts
Outdated
const rv = Super.extend(options); | ||
|
||
for(let sttc in Component) | ||
if(!(sttc in function() {}) && Component.hasOwnProperty(sttc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if hasOwnProperty
will impact component inheritance. A test case should be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Written like that, a child class doesn't forward the statics of its parent. hasOwnProperty
means the the property is in the object, not its prototype.
I am not sure of the question, therefore I don't know if it answers - what do you mean by "impact component inheritance" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider
@Compoent class Parent extends Vue { static config = {} }
@Compoent class Child extends Parent {}
Child.config // expect an object {}
Written like that, a child class doesn't forward the statics of its parent.
I think you already understand me. And I even suspect whether we should support inheritance any way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, Child.config
would, in this implementation, retrieve undefined
Beside beeing the easiest to implement, I just checked on how typescript managed static' legacy, and it seems coherent with the usual behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it simple. vue-class-component is for both Babel and TS users. Rolling out a babel compatible version might be challenging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, is it still a "change requested" or an acceptation?
src/component.ts
Outdated
const rv = Super.extend(options); | ||
|
||
for(let sttc in Component) | ||
if(!(sttc in function() {}) && Component.hasOwnProperty(sttc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!(sttc in function() {})
Is this necessary? Looks like only using hasOwnProperty
is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will for instance avoid statics to override name
or apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shouldn't they be overridden? Is that stated in the spec?
I think we should follow the es spec as possible since the user would expect it.
src/component.ts
Outdated
|
||
for(let sttc in Component) | ||
if(!(sttc in function() {}) && Component.hasOwnProperty(sttc)) | ||
rv[sttc] = Component[sttc]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename rv
to Extended
and also sttc
to key
? I cannot see what the current name means...
src/component.ts
Outdated
return Super.extend(options) | ||
const rv = Super.extend(options); | ||
|
||
for(let sttc in Component) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add curly braces for for
and if
expressions?
@ktsn this implementation is not compatible with Babel, is this fine to you? |
@HerringtonDarkholme I think it's ok that it does not have partial feature of class like inheritance since we can incrementally add them when we need. But at least it should be consistent with es spec that we include into vue-class-component. |
Sorry for latency. |
@HerringtonDarkholme This looks good to me. Would you have any concern for this feature/implementation still? |
#135 (comment)
Class' static member are browsed and added to the generated class.